package com.example.myapplication;


import android.content.ClipData;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.security.acl.Group;
import java.util.ArrayList;


public class dispose  extends BaseExpandableListAdapter {
   private ArrayList<Group> groups;
   private ArrayList<ArrayList<ClipData.Item>> iDate;
   private Context mcontext;
   public dispose(ArrayList<Group> groups, ArrayList<ArrayList<ClipData.Item>> iDate, Context mcontext){
       this.groups=groups;
       this.iDate=iDate;
       this.mcontext=mcontext;
   }
   @Override
    public int getGroupCount() {
        return groups.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return iDate.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return iDate.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
       ViewHolder viewHolder;
       if (convertView==null){
             convertView= LayoutInflater.from(mcontext).inflate(R.layout.layout,parent,false);
            viewHolder=new ViewHolder();
            viewHolder.tv_group_name=(TextView)convertView.findViewById(R.id.tv_group);
            convertView.setTag(viewHolder);
         }else {
           viewHolder= (ViewHolder)convertView.getTag();
       }
       viewHolder.tv_group_name.setText(groups.get(groupPosition).getName());
       return convertView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
       ViewHolderItem itemHolder;
       if (convertView==null){
           convertView=LayoutInflater.from(mcontext).inflate(R.layout.layout2,parent,false);
           itemHolder=new ViewHolderItem();
           itemHolder.img_icom=(ImageView)convertView.findViewById(R.id.img_icon);
           itemHolder.tv_name=(TextView)convertView.findViewById(R.id.tv_name);
           convertView.setTag(itemHolder);
       }else {
           itemHolder=(ViewHolderItem)convertView.getTag();
       }
       itemHolder.img_icom.setImageResource(iDate.get(groupPosition).get(childPosition).getiId());
       itemHolder.tv_name.setText(iDate.get(groupPosition).get(childPosition).getiName());
       return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }
    private static  class ViewHolder{
       private TextView tv_group_name;
    }
    private static class ViewHolderItem{
       private ImageView img_icom;
       private TextView tv_name;
    }
}
